<?php

namespace app\traits;

use app\common\Jwt;

trait UserTrait
{
    /**
     * 获取用户ID
     * @param $adminId
     * @return mixed
     */
    public function getUid($adminId = 0)
    {
        return app()->request->user->uid ?? $adminId;
    }

    /**
     * 从token获取UID
     * @param $token
     * @return array
     */
    public function getUidFromToken($token)
    {
        [$isOk, $result] = Jwt::parseUserInfo($token, 'api');
        return $result['user']->uid;
    }
}